﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Syspetro.Core.Extensions
{
    public static class RegexHelper
    {
        /// <summary>
        /// 手机号格式校验
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static bool IsPhone(this string code)
        {
            try
            {
                Regex regex = new(@"^\d{11}$");
                return regex.IsMatch(code);
            }
            catch
            {
                return true;
            }
        }
        /// <summary>
        /// Email格式校验
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static bool IsEmail(this string code)
        {
            try
            {
                Regex regex = new(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
                return regex.IsMatch(code);
            }
            catch
            {
                return true;
            }
        }
        /// <summary>
        /// 密码校验
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static bool IsPassword(this string code)
        {
            try
            {
                Regex regex = new(@"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$");
                return regex.IsMatch(code);
            }
            catch
            {
                return true;
            }
        }
    }
}
